package com.jinbooks.web.login.service;


import com.jinbooks.authn.dto.LoginVo;
import com.jinbooks.authn.jwt.AuthJwt;
import com.jinbooks.exception.ServiceException;
import com.jinbooks.util.SpringUtils;
import org.springframework.security.core.Authentication;

/**
 * 授权策略
 *
 * @author Michelle.Chung
 */
public interface IAuthStrategy {

    String BASE_NAME = "AuthStrategy";

    /**
     * 登录
     *
     * @param authentication      登录对象
     * @param grantType 授权类型
     * @return 登录验证信息
     */
    static AuthJwt login(Authentication authentication, String grantType) {
        // 授权类型和客户端id
        String beanName = grantType + BASE_NAME;
        if (!SpringUtils.containsBean(beanName)) {
            throw new ServiceException("授权类型不正确!");
        }
        IAuthStrategy instance = SpringUtils.getBean(beanName);
        return instance.login(authentication);
    }

    /**
     * 登录
     *
     * @param authentication   登录对象
     * @return 登录验证信息
     */
    AuthJwt login(Authentication authentication);

}
